<%--
  Created by IntelliJ IDEA.
  User: zplogo
  Date: 2017/10/30
  Time: 9:13
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>zTree简单数据格式延迟加载</title>
    <link type="text/css" rel="stylesheet" href="assets/css/zTreeStyle/zTreeStyle.css">
    <script type="text/javascript" src="assets/js/jquery-1.8.3.js"></script>
    <script type="text/javascript" src="assets/js/jquery.ztree.all-3.5.min.js"></script>
    <script type="text/javascript" src="assets/js/jquery.ztree.exhide-3.5.min.js"></script>
    <style>
        .content{
            width:300px;
            height: 600px;
            /*background-color: #00ff00;*/
            overflow: auto;
        }
    </style>
    <script>
        var zTreeObj;

        var setting = {
            view: {
                dblClickExpand: false,
                showLine: true,
                selectedMulti: false,
                expandSpeed: "fast"
            },
            callback: {
                onDblClick: zTreeOnDblClick
            },
            data:{
                key:
                    {
                        name: "treeNodeName"  //界面显示的名称参数
                    },
                simpleData:
                    {
                        enable: true,
                        idKey: "treeId",
                        pIdKey: "treePid",
                        rootPId: "0"
                    }
            }
            ,async: {
                enable: true,
                url:"/zTree/asynchInitData.do",
                autoParam:["treeId","isParent"],
                dataFilter: filter
            }
            ,callback:{
                asyncSuccess: zTreeOnAsyncSuccess,
                asyncError: zTreeOnAsyncError,
                beforeClick:beforeClick
            }
        };

        function filter(treeId, parentNode, childNodes) {
            if (!childNodes) return null;
            /*for (var i=0, l=childNodes.length; i<l; i++) {
                childNodes[i].name = childNodes[i].name.replace('','');
            }*/
            return childNodes;
        }

        function beforeClick(treeId,treeNode){
            if(!treeNode.isParent){
                alert("请选择父节点");
                return false;
            }else{
                return true;
            }
        }

        function zTreeOnAsyncError(event, treeId, treeNode){
            alert("异步加载失败!");
        }

        function zTreeOnAsyncSuccess(event, treeId, treeNode, msg){

        }

        function zTreeOnDblClick() {
            alert("zTree双击事件");
        }

        var zNodes=[];

        $(function () {
                zTreeObj = $.fn.zTree.init($("#tree"), setting, zNodes);
        });
    </script>
</head>
<body>
<div class="content">
    <ul id="tree" class="ztree"></ul>
</div>
</html>
